Skip to content

Add test for WrongType exception propagation in query_one_optional#6326

Merged
willmcgugan merged 2 commits into
mainfrom
copilot/sub-pr-6325
Jan 14, 2026
Merged

Add test for WrongType exception propagation in query_one_optional#6326
willmcgugan merged 2 commits into
mainfrom
copilot/sub-pr-6325

Conversation

Copilot AI commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

The test_query_one_optional test did not verify that WrongType exceptions propagate correctly when a widget is found but has an incorrect type, despite this behavior being documented in the method's docstring.

Changes

  • Added test case verifying WrongType is raised when query_one_optional("#foo", Label) is called on an Input widget
  • Mirrors the pattern used in test_query_error for consistency
# Verify that WrongType exceptions still propagate
with pytest.raises(WrongType):
    # Asking for a Label, but the widget is an Input
    app.query_one_optional("#foo", Label)

This ensures query_one_optional maintains its documented contract: catch NoMatches (return None), but propagate WrongType.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: willmcgugan <554369+willmcgugan@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on optional query implementation Add test for WrongType exception propagation in query_one_optional Jan 14, 2026
Copilot AI requested a review from willmcgugan January 14, 2026 21:41
Base automatically changed from query-one-optional to main January 14, 2026 21:42
@willmcgugan willmcgugan marked this pull request as ready for review January 14, 2026 21:46
@willmcgugan willmcgugan merged commit 43189c4 into main Jan 14, 2026
1 check passed
@willmcgugan willmcgugan deleted the copilot/sub-pr-6325 branch January 14, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants